﻿import com.dinmax.isolution.*

class WindowThemesGUI
extends AppWindowGUI {
	
	//variables de dibujo
	private var mcContainer:MovieClip;
	
	private var activeTheme:MovieClip;
	private var themes:Array;
	
	public function showContent(){
		super.showContent();
		trace("WindowThemesGUI | debo pedir los temas al HCC");
		trace("WindowThemesGUI | debo mostrar los temas al HCC");
				
		this.setThemes(HCC.getThemes());
		
		var nY:Number = 15;
		
		//itero en los temas
		for(var i:Number = 0; i < themes.length; i ++){
							
			var theme:ThemeGUI = ThemeGUI(this.mcContainer.attachMovie("ThemeGUI", "mcTheme"+i, this.mcContainer.getNextHighestDepth()));
			theme._x = 15;
			theme._y = nY;
			nY += theme._height + 5;
			theme.setTheme(themes[i]);
			
			var root:WindowThemesGUI = this;
			theme["mcBase"].onPress = function(){
				this._parent.setSelected(!this._parent.getSelected());
				if(root.activeTheme != this._parent) root.activeTheme.setSelected(false);
				root.activeTheme = this._parent;
			}
			
				
		}
		
		return;
	}
	
	public function showThemeView(theme:Theme):Void {
		//TODO esto está standby por ahora
		/*
		var editor:ThemeEditorGUI = this["mcEditor"].attachMovie("ThemeEditorGUI", "mcEditor", 1);
		editor.setTheme(theme);
		*/
		return;
	}
	
	public function setThemes(themes:Array):Void {
		this.themes = themes;
		return;
	}
	
	public function updateTheme(theme:Theme):Void {
		// TODO esto está re choto hecho
		
		var nInstance:Number = 0;
		while(this.mcContainer["mcTheme"+nInstance]){
			if(this.mcContainer["mcTheme"+nInstance].getTheme().getId() == theme.getId()){
				this.mcContainer["mcTheme"+nInstance].setTheme(theme);
			}
			nInstance++;
		}
			
		if(this["mcEditor"].mcEditor.getTheme().getId() == theme.getId()){
			this["mcEditor"].mcEditor.setTheme(theme);
		}
		return;
	}
}